using System;

namespace ExcelTemplateEngine.Configuration
{
    public class ConfigurationBuilder
    {
        private readonly DefaultTemplateEngineConfiguration _config;
        
        public ConfigurationBuilder()
        {
            _config = new DefaultTemplateEngineConfiguration();
        }
        
        public ConfigurationBuilder WithMaxRows(int maxRows)
        {
            _config.MaxRows = maxRows;
            return this;
        }
        
        public ConfigurationBuilder WithMaxColumns(int maxColumns)
        {
            _config.MaxColumns = maxColumns;
            return this;
        }
        
        public ConfigurationBuilder WithDebugMode(bool debugMode = true)
        {
            _config.DebugMode = debugMode;
            return this;
        }
        
        public ConfigurationBuilder WithTempDirectory(string tempDirectory)
        {
            _config.TempDirectory = tempDirectory;
            return this;
        }
        
        public ConfigurationBuilder WithDefaultFillMode(FillMode fillMode)
        {
            _config.DefaultFillMode = fillMode;
            return this;
        }
        
        public ConfigurationBuilder WithConcurrency(bool enabled, int? maxLevel = null)
        {
            _config.EnableConcurrency = enabled;
            if (maxLevel.HasValue)
                _config.MaxConcurrencyLevel = maxLevel.Value;
            return this;
        }
        
        public ConfigurationBuilder WithPerformanceMonitoring(
            bool enabled = true, 
            TimeSpan? warningThreshold = null, 
            bool logSlowOperations = true)
        {
            _config.Performance.EnablePerformanceMonitoring = enabled;
            if (warningThreshold.HasValue)
                _config.Performance.PerformanceWarningThreshold = warningThreshold.Value;
            _config.Performance.LogSlowOperations = logSlowOperations;
            return this;
        }
        
        public ITemplateEngineConfiguration Build()
        {
            _config.Validate();
            return _config;
        }
    }
}